<template>
  <el-row class="seal-manage-module">
    <el-col class="title">需求应答</el-col>
    <el-col class="main-content">
      <item-title :detailInfo="detailInfo"></item-title>
      <item-detail :detailInfo="detailInfo">
        <el-button type="text" @click="routerToDemand">查看原需求</el-button>
      </item-detail>
    </el-col>
  </el-row>
</template>
<script>
import ItemTitle from "./ItemTitle";
import ItemDetail from "./ItemDetail";
import { getProductMaterial } from "@/api";
export default {
  name: "demandAnswer",
  components: {
    ItemDetail,
    ItemTitle
  },
  data() {
    const validPrice1 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入价格下限"));
      } else {
        if (this.publishForm.price2 !== "") {
          this.$refs.publishForm.validateField("price2");
        }
        callback();
      }
    };
    const validPrice2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入价格上限"));
      } else if (value < this.publishForm.price1) {
        callback(new Error("价格上限不能小于下限"));
      } else {
        callback();
      }
    };
    return {
      detailInfo: {},
      activeName: "1",
      publishForm: {
        demandTitle: "",
        demandCategory: "",
        categoryList: [
          { label: "category1", value: 1 },
          { label: "category2", value: 2 }
        ],
        link: "",
        demand: "",
        type: ["尺寸图", "3D 渲染图"],
        price1: "",
        price2: "",
        date: "",
        product: ""
      },
      rules: {
        demandTitle: [{ required: true, message: "必填", trigger: "blur" }],
        demandCategory: [
          { required: true, message: "必选", trigger: "change" }
        ],
        type: [{ required: true, message: "必选", trigger: "change" }],
        price1: [{ validator: validPrice1, trigger: "blur" }],
        price2: [{ validator: validPrice2, trigger: "blur" }],
        product: [{ required: true, message: "请上传图片", trigger: "submit" }]
      },
      actionUrl: "https://jsonplaceholder.typicode.com/posts/",
      imageUrl: ""
    };
  },
  created() {
    this.detailInfo.itemTitle = "蒸豪华商务沙发";
    this.detailInfo.itemSubTitle = "实木沙发";
    this.detailInfo.companyTitle = "菲林格尔家居科技股份有限公司";
    this.detailInfo.tagList = [
      { content: "环保认证", color: "danger" },
      { content: "水性漆", color: "" },
      { content: "独有工艺", color: "warning" }
    ];
    this.detailInfo.cost = "5500.00";
    this.detailInfo.ddl = "2020-08-09";
  },
  methods: {
    routerToDemand() {
      console.log(this);
    },
    beforeUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt3M = file.size / 1024 / 1024 < 3;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt3M) {
        this.$message.error("上传头像图片大小不能超过 3MB!");
      }
      return isJPG && isLt3M;
    },
    uploadSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    validateDraft(cb) {
      this.$refs.publishForm.validate(valid => {
        if (valid) {
          cb();
        }
      });
    },
    save() {
      console.log("save");
    },
    draftSave() {
      this.validateDraft(this.save);
    },
    draftPublish() {}
  }
};
</script>
<style lang="scss" scoped>
.custom-label {
  /deep/.el-form-item__label {
    &::after {
      display: block;
      content: "(可多选)";
      margin-left: 15px;
      font-size: 12px;
      color: #cccccc;
    }
  }
}
.product-uploader {
  display: inline-block;
  /deep/.el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;

    &:hover {
      border-color: #409eff;
    }

    .product-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      line-height: 178px;
      text-align: center;
    }
  }
}
li {
  list-style: none;
}
.upload-limit {
  padding-left: 5px;
  width: 200px;
  border: 1px solid #e6e6e6;
  color: #e6e6e6;
}
.mb-10 {
  margin-bottom: 10px;
}
.clearfix {
  &:after {
    visibility: hidden;
    display: block;
    font-size: 0;
    content: " ";
    clear: both;
    height: 0;
  }
}
.fl {
  float: left;
}
.fr {
  float: right;
}
.seal-manage-module {
  .title {
    margin-bottom: 20px;
    padding: 0 10px;
    height: 60px;
    line-height: 60px;
    box-shadow: 0px 2px 4px 0px #d1d9e2;
  }
  .main-content {
    background-color: #fff;
    padding: 10px;

    .seal {
      text-align: center;
      font-size: 16px;
      .card-title {
        color: #4d4d4d;
        font-weight: 500;
        margin: 10px 0;
      }
      .card-content {
        color: #808080;
        font-weight: 400;
        margin-bottom: 20px;
      }
    }
    .table {
      margin: 10px 0;
      .delete-btn {
        color: red;
      }
    }
  }
}
</style>